package models

import (
	"gorm.io/gorm"
)

// TriviaQuestion 冷知识题目模型
type TriviaQuestion struct {
	gorm.Model
	CircleID      uint   `json:"circle_id"`                          // 所属兴趣圈ID
	Question      string `json:"question" gorm:"type:text;not null"` // 问题内容
	OptionA       string `json:"option_a" gorm:"size:255"`
	OptionB       string `json:"option_b" gorm:"size:255"`
	OptionC       string `json:"option_c" gorm:"size:255"`
	OptionD       string `json:"option_d" gorm:"size:255"`
	CorrectAnswer string `json:"correct_answer" gorm:"size:1;not null"`      // A/B/C/D
	Difficulty    string `json:"difficulty" gorm:"size:20;default:'medium'"` // easy, medium, hard
	Status        string `json:"status" gorm:"size:20;default:'active'"`     // active, inactive
}

// CreateTriviaQuestion 创建新题目
func CreateTriviaQuestion(question *TriviaQuestion) error {
	return GetDB().Create(question).Error
}

// GetQuestionsByCircleID 获取圈子的题目列表
func GetQuestionsByCircleID(circleID uint, limit int) ([]TriviaQuestion, error) {
	var questions []TriviaQuestion
	result := GetDB().Where("circle_id = ? AND status = ?", circleID, "active").
		Order("RAND()").
		Limit(limit).
		Find(&questions)
	return questions, result.Error
}
